package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne;

/**
 * @author yaoxuguang
 * @Title: yao-interview
 * @Package com.yaoxuguang.concurrence.wait_notify.producer_consumer.ontToOne
 * @Description: 生产者
 * @date 2018年12月21日17:56
 */
public class Producer {
    private String lock;

    public Producer(String lock) {
        this.lock = lock;
    }
    public void setValue(){
        try {
            synchronized (lock){
                if(!ValueObject.value.equals("")){
                    lock.wait();
                }
                String value = System.currentTimeMillis()+"_"+System.nanoTime();
                System.out.println("生产者set的值是："+value);
                ValueObject.value = value;
                lock.notify();
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
